{extend name='template/base'}{/extend}
{block name='style'}
{/block}
{block name='script'}

{/block}
{block name='content'}
<div class="row">
    <div class="col-xs-12">
        <div class="box box-primary">
            <div class="box-body">
                <div id="toolbar">
                    <div class="btn-group pull-left mr10">
                        <a class="btn btn-primary" id="add_btn"><i class="fa fa-plus"></i> 新增</a>
                    </div>
                </div>
                <table id="table"
                       data-toggle="table"
                       data-show-refresh="true"
                       data-side-pagination="server"
                       data-pagination="true"
                       data-url="{:url('WechatMessageTemplate/index_data')}"
                >
                    <thead>
                    <tr>
                        <th data-field="id">编号</th>
                        <th data-field="title">模板标题</th>
                        <th data-field="template_short_id">模板编号</th>
                        <th data-field="template_id">模板ID</th>
                        <th data-field="status" data-formatter="formatStatus">是否启用</th>
                        <th data-field="operate" data-formatter="formatOperate" data-events="operateEvents" >操作</th>
                    </tr>
                    </thead>
                </table>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
    </div><!-- /.col -->
</div><!-- /.row -->

{/block}
{block name='script_extra'}
<script>
    var add_data_url="{:url('WechatMessageTemplate/add_data')}";
    var edit_data_url="{:url('WechatMessageTemplate/edit_data')}";
</script>
<script>
    //格式化掉 末尾 .html
    function urlFormat(url) {
        if (url.indexOf('.html'))
        {
            url = url.replace('.html', '');
        }
        return url;
    }
    // <editor-fold defaultstate="collapsed" desc="添加">
    $('#add_btn').on('click',function(){
        layer_open('新增文本回复',add_data_url);
    });
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作">
    function formatOperate(value, row, index) {
        return '<button class="btn btn-default btn-sm row_edit mr10" href="javascript:void(0)">' +
                ' 修改'+
                '</button>&nbsp;'+
                '<button class="btn btn-default btn-sm row_delete mr10" href="javascript:void(0)">'+
                ' 删除'+
                '</button>'
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="操作函数">
    window.operateEvents = {
        'click .row_edit': function (e, value, row, index) {
            layer_open('修改',urlFormat(edit_data_url)+'/id/'+row.id);
        },
        'click .row_delete': function (e, value, row, index) {
            var data = {
                id: row.id
            };
            layer.confirm('你确定要删除该选项吗？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    dataType:'json',
                    data:data,
                    url:delete_data_url,
                    success:function(res){
                        if(res.success == false){
                            layer.alert(res.message,{icon:5})
                        }else{
                            layer.msg(res.message,{time:1000},function(){
                                table.bootstrapTable('refresh');
                                layer_close();
                            });

                        }
                    }
                })
            })
        }
    };

    // </editor-fold>


    // <editor-fold defaultstate="collapsed" desc="定义状态">
    function formatStatus(value,row,index) {
        if (parseInt(value) == 1) {
            return '<i class="fa fa-check-circle text-green" title="启用">启用</i>';
        }
        if (parseInt(value) == 0) {
            return '<i class="fa fa-minus-circle text-yellow" title="禁用">禁用</i>';
        }
    }

</script>
{/block}